﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FreeProperty.Views.Shared;

namespace FreeProperty.Views.Passport
{
    public partial class SearchPassportProvider : SiteBasePage
    {
        public delegate void SimpleDelegate();
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetUI();
            }
            if (hdnMode.Value == "Search")
            {
                Session.Clear();
                Provider oProvider = new Provider();
                SearchParametersVO oSearchParametersVO = FillSearchParameters();
                List<ProviderVO> lstProviders = oProvider.SearchProviders(oSearchParametersVO);
                if (lstProviders.Count > 0)

                {
                    Session[FreePropertyConstants.SESSION_PROVIDER_SEARCH] = lstProviders;
                    Server.Transfer("~/Views/ProviderDirectory/SearchPassportProviderResults.aspx");
                }
                else
                {
                    lblError.Text = "No records were found matching your search criteria.";
                }
                
            }
        }
        private SearchParametersVO FillSearchParameters()
        {
            SearchParametersVO oSearchParametersVO = new SearchParametersVO();
            oSearchParametersVO.Zipcode = FreePropertySettings.GetDBString(tbZipCode.Value.Trim());
            oSearchParametersVO.Distance = Convert.ToInt32(ddlDistance.SelectedValue);

            oSearchParametersVO.County = ddlCounty.SelectedValue;

            oSearchParametersVO.LastName = FreePropertySettings.GetDBString(tbLastName.Value.Trim());;
            oSearchParametersVO.FirstName = FreePropertySettings.GetDBString(tbFirstName.Value.Trim());;
            oSearchParametersVO.OfficeName = FreePropertySettings.GetDBString(tbOfficeName.Value.Trim());
            oSearchParametersVO.Speciality = ddlSpeciality.SelectedValue;

            return oSearchParametersVO;
        }
        private void SetUI()
        {
            FreePropertyUtil.BindNameValue(ddlDistance, FreePropertyConstants.CACHE_DISTANCE);
            FreePropertyUtil.BindNameValue(ddlCounty, FreePropertyConstants.CACHE_COUNTY);
            FreePropertyUtil.BindNameValue(ddlSpeciality, FreePropertyConstants.CACHE_SPECIALITY);
            FreePropertyUtil.BindNameValue(ddlLanguage, FreePropertyConstants.CACHE_LANGUAGE);
        }
        
    }
}